﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        
        string sname = username.Text;
        string spwd = password.Text;
        string scode = code.Text.ToUpper();

        if (scode == "")
        {            
            Common.Jscript.AlertAndRedirect("验证码不能为空", "login.aspx");
            return;
        }
        if (sname == "")
        {
            Common.Jscript.AlertAndRedirect("用户名不能为空", "login.aspx");
            return;
        }
        if (spwd == "")
        {
            Common.Jscript.AlertAndRedirect("密码不能为空", "login.aspx");
            return;
        }

        string strCheckCode = Request.Cookies.Get("CheckCode").Value;
        if (strCheckCode == null || strCheckCode != scode)
        {
            Common.Jscript.AlertAndRedirect("验证码错误,", "login.aspx");
            return;
        }
        BLL.UserBLL uBLL = new BLL.UserBLL();
        Model.SessionUser suser = uBLL.Login(sname, spwd);
        if (suser == null  )
        {
            Common.Jscript.AlertAndRedirect("用户名或密码输入错误！", "login.aspx");
            return;
        } 
        if(suser.state == 1)
        {
            Common.Jscript.AlertAndRedirect("用户被停用！", "login.aspx");
            return;
        }
        BaseLogin.SetSession(HttpContext.Current, suser);

        //日志
        BLL.SysLogBLL.AddLogInfo(suser, Model.enumLogDesNO.LOG_DES_LOGIN, "login.aspx", HttpContext.Current.Request.UserHostAddress);
        switch (suser.type)
        { 
            case 0:
            case 1:
                Response.Redirect("Manager/main.aspx");
                break;
            case 2:
                Response.Redirect("Vendor/Vendor_Main.aspx");
                break;
            case 3:
                Response.Redirect("Custom/Custom_Main.aspx");
                break;
            case 4:
                Response.Redirect("OutsourcingSupplier/WaiJi_Main.aspx");
                break;
        }


         
    }
}
